package com.cjd.view.corona;

import android.content.Context;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

/**
 * 时间轮盘自定义view
 * Created by chenjidong on 2019/4/17.
 */
public class TimeCoronaSurfaceView extends SurfaceView implements SurfaceHolder.Callback {

    TimeCoronaController timeCoronaController;
    private Context context;

    public TimeCoronaController getTimeCoronaController() {
        return timeCoronaController;
    }

    public TimeCoronaSurfaceView(Context context) {
        super(context);
        init(context);
    }

    public TimeCoronaSurfaceView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public TimeCoronaSurfaceView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }


    private void init(Context context) {
        this.context = context;
        getHolder().addCallback(this);
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        timeCoronaController = new TimeCoronaController(context, getHolder());
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        if (timeCoronaController != null)
            timeCoronaController.onDestroy();
    }
}
